<?
include 'includes/specs_functions.php';
echo printGoogleAnalytics();
#------------------------------------------------------------------------
# Connect to PADS
$DB = getDB();
#-------------------------------$Session information
$SESSION = get_session($DB);
$userCICUID = $SESSION->Character;
$THEME = $_POST["THEME"];
$userAVATAR = $SESSION->GetCharacter('avatar');
$padCICUID = $_POST['CICUID'];
$padAVATAR = $_POST['AVATAR'];
#---------------------------------------------------
//Show($SESSION->GetCharacter('id'));
//Show($SESSION->GetCharacter('avatar'));

$sId = $_POST['specId'];
$amount = $_POST['amount'];

//$padCICUID = 9545338;  // Nemi Chan

if (isset($_POST['specId']) && isset($_POST['amount'])){

	$output = "
				<script type='text/javascript'>
					$(function(){
						$('.ratings').children().not(':radio').hide();
						$('.ratings').stars({
							disabled: true
						});
					});
					
					$(document).ready(function(){
						$('.more-comment').click(function(e) {
							loadWidgetRatings(".$sId.",".($amount+5).");
						});
					});
				</script>
				<table style='width:100%'>";
				
					
				$abfrage = "
				SELECT rate.".SPEC_TBL_RATINGS_USER_ID." as uId 
					,rate.".SPEC_TBL_RATINGS_ID." as id
					,rate.".SPEC_TBL_RATINGS_SPEC_ID." as specId
					,(CASE WHEN rate.".SPEC_TBL_RATINGS_CDATE."= rate.".SPEC_TBL_RATINGS_UDATE." THEN 'rated this spec with' ELSE 'updated his rating to' END) as comment
					,DATE_FORMAT(rate.".SPEC_TBL_RATINGS_CDATE.",'%b %d %Y') as c_udate
					,user.".TBL_CHARACTERS_NAME." as Name
					,user.".TBL_CHARACTERS_AVATAR." as Avatar
					,rate.".SPEC_TBL_RATINGS_VALUE." as value
					,'RATE' as type
					
				FROM (".SPEC_TBL_RATINGS." as rate
				INNER JOIN ".TBL_CHARACTERS." as user
				ON user.".TBL_CHARACTERS_CICUID." = rate.".SPEC_TBL_RATINGS_USER_ID.")
				WHERE rate.".SPEC_TBL_RATINGS_SPEC_ID." = \"".$sId."\"
				ORDER BY DATE_FORMAT(rate.".SPEC_TBL_RATINGS_CDATE.",'%b %d %Y ') DESC";

				$result = $DB->RawQuery($abfrage);

				$num = $result[0];	
				$i = 1;

				
				if($num>0){
					foreach ($result[2] as $row) {
						$MyAvatar = "<div class='border-av'><img class='avatar-pic' style='width:36px;' src='".$row['Avatar']."?".time()."'/></div>";

			$output .= "<tr class='border-bottom' >
							<td class='ver-top cur-point' style='border-bottom: solid 1px #F4F4F4;' width='22%'>
								<a class='cur-point' name='no' href='?".$row['uId']."'>".$MyAvatar."</a>
							</td>
							<td class='td-table ver-top' style='border-bottom: solid 1px #F4F4F4;' width='78%'>
								<div >
									<a class='cur-point bold-text' name='no' style='font-size:10px' href='?".$row['uId']."'>".$row['Name']."</a>
									<div  style='padding-left:5px; padding-top: 2px; width: 80px;'> 
										<form class='ratings' action='' method='post'>";
												
								foreach (get_options() as $id => $title){
									$output .= 	"<input type='radio' name='rate' value='".$id."' id='rate".$id."'";
									if($id==$row['value']){
										$output .= 	" checked";
									}
									$output .= 	" />";
								}
								
						$output .= "	</form>
									</div>
									<div style='clear:both;'/>
									<div class='normal-text font-10 fl-left'>
											<div class='op-4 fl-left' style='padding-bottom:5px; padding-right:5px;'>".$row['c_udate']."</div>
									</div>
								</div>
							</td>
						</tr>";
							if($i == $amount){
							break;
						}
						$i++;
					}
				}
				
				if($i<$num){
					// MORE COMMENTS TO SHOW
					$output .= "<tr>
						<td  colspan='2' style='text-align: center;padding-top: 10px;'>
							<div class='more-comment center cur-point arrow-down' style='display:inline;'/>
						</td>
					</tr>";
					
				}
			
		$output .= "</table><div style='clear:both;'>";

	echo  $output;
}

#------------------------------------------------------------------------
# Disconnect
leaveDB($DB);

?>